package com.medusa.aps.business.modules.basic.model;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import lombok.experimental.Accessors;

import java.io.Serializable;
import java.time.LocalDate;

/**
 * @author 张治保
 * @since 2023/10/9
 */
@Getter
@Setter
@ToString
@EqualsAndHashCode(of = "date")
@Accessors(chain = true)
@Schema(description = "当月日期与星期")
public class MonthDayWeek implements Serializable {

    /**
     * 日期
     */
    @Schema(description = "日期")
    private LocalDate date;

    /**
     * 当月的第几天
     */
    @Schema(title = "日期", description = "表示当月的第几天 取值范围 1-31")
    private Integer day;


    @Schema(title = "星期", description = "取值范围 1-7")
    private Integer week;

    /**
     * 日期 转换为 MonthDayWeek
     *
     * @param date 日期
     * @return MonthDayWeek
     */
    public static MonthDayWeek of(LocalDate date) {
        return new MonthDayWeek().setDate(date).setDay(date.getDayOfMonth()).setWeek(date.getDayOfWeek().getValue());
    }
}
